package com.cevent.zhanniu.business.controller;/**
 * Created by Cevent on 2020/11/21.
 */

import com.cevent.zhanniu.server.domain.ZncmsAdmin;
import com.cevent.zhanniu.server.dto.AdminDto;
import com.cevent.zhanniu.server.dto.PageDto;
import com.cevent.zhanniu.server.dto.ResponseDto;
import com.cevent.zhanniu.server.service.ZmcmsAdminService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author cevent
 * @description
 * @date 2020/11/21 14:48
 */
@RestController
@RequestMapping("/admin")
public class ZncmsAdminController {
    private static final Logger LOG= LoggerFactory.getLogger(ZncmsAdminController.class);
    @Resource
    private ZmcmsAdminService adminService;

    @RequestMapping("/selectById")
    public List<ZncmsAdmin> getAdminList(){
        return adminService.getAdmins();
    }

    //1.获取admin-dto对象
    @RequestMapping("/adminDTO")
    public List<AdminDto> getAdminDTO(){
        return adminService.getAdminDto();
    }

    //2.分页获取admin-dto-list
    @RequestMapping("/adminPageDTOS")
    public ResponseDto getAdminPageDTOS(@RequestBody PageDto pageDto){
        ResponseDto responseDto=new ResponseDto();
        adminService.getAdminPageDTO(pageDto);
        LOG.info("admin输出的page对象：{}",pageDto);

        responseDto.setResponseData(pageDto);

        return responseDto;
    }

    //3.新增admin
    @RequestMapping("/adminAdd")
    public ResponseDto adminAdd(@RequestBody AdminDto adminDto){
        ResponseDto responseDto=new ResponseDto();
        LOG.info("新增的admin对象",adminDto);
        adminService.addAdmin(adminDto);
        responseDto.setResponseData(adminDto);
        return responseDto;
    }
}
